<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>

<script>
var canvas = document.createElement('canvas');
canvas.width = 5;
canvas.height = 5;
var ctx = canvas.getContext('2d');

function getPutImageData(numIters, ctx, rgba) {
    var x = 0, y = 0, w = ctx.canvas.width, h = ctx.canvas.height;

    // Paint the canvas green to start
    ctx.fillStyle = color;
    ctx.fillRect(x,y,w,h);

    // Now paint the canvas a random hue of gray
    var color = 'rgba(' + rgba + ')'; 
    ctx.fillStyle = color;
    ctx.fillRect(x,y,w,h);

    // Get the current "original" image data
    var origImageData = ctx.getImageData(x, y, w, h);
    ctx.putImageData(origImageData, x, y);

    // Get and put the image data 'numIters' times
    for(var i = 0; i < numIters; i++)
        ctx.putImageData(ctx.getImageData(x, y, w, h), x,y);

    // Grab new current image data
    var currImageData = ctx.getImageData(x, y, w, h);

    // Verify that original and new current image datas are equal
    var dataMatch = true;
    for(var i = 0; i < currImageData.data.length; i++)
        if (origImageData.data[i] != currImageData.data[i]) {
            dataMatch = false;
            break;
        }
    assert_true(dataMatch);
}

var testScenarios = [
    ['GetPutImageDataTestCase0 ', 50, ctx, '0, 0, 0, 0.0'],
    ['GetPutImageDataTestCase1 ', 50, ctx, '0, 0, 0, 0.5'],
    ['GetPutImageDataTestCase2 ', 50, ctx, '0, 0, 0, 1.0'],
    ['GetPutImageDataTestCase3 ', 50, ctx, '127, 128, 129, 0.49'],
    ['GetPutImageDataTestCase4 ', 50, ctx, '127, 128, 129, 0.51'],
    ['GetPutImageDataTestCase5 ', 50, ctx, '127, 128, 129, 0.5'],
    ['GetPutImageDataTestCase6 ', 50, ctx, '128, 128, 128, 0.0'],
    ['GetPutImageDataTestCase7 ', 50, ctx, '128, 128, 128, 0.5'],
    ['GetPutImageDataTestCase8 ', 50, ctx, '128, 128, 128, 1.0'],
];

generate_tests(getPutImageData, testScenarios);

</script>
